﻿using System.Windows.Input;

namespace WpfUIUtilities.Gestures
{
  /// <summary>
  /// Represents a gesture being "valid" when the CTRL key is pressed and the mouse wheel is scrolling down.
  /// Usage: <MouseBinding Gesture="{x:Static Gestures:MouseWheelDownKeyCtrlGesture.Instance}" Command="{Binding ZoomDownCommand}" />
  /// </summary>
  public class MouseWheelDownKeyCtrlGesture : MouseGesture
  {
    #region fields

    #endregion

    #region constructors

    /// <summary>
    /// Creates a new <see cref="MouseWheelDownKeyCtrlGesture"/> instance.
    /// </summary>
    /// <param name="modifierKeys"></param>
    protected MouseWheelDownKeyCtrlGesture(ModifierKeys modifierKeys) : base(MouseAction.WheelClick, modifierKeys)
    {
      // Intentionally left blank.
    }

    #endregion

    #region properties

    /// <summary>
    /// Returns a new <see cref="MouseWheelDownKeyCtrlGesture"/> instance.
    /// </summary>
    public static MouseWheelDownKeyCtrlGesture Instance
    {
      get
      {
        return new MouseWheelDownKeyCtrlGesture(ModifierKeys.Control);
      }
    }

    #endregion

    #region methods

    public override bool Matches(object targetElement, InputEventArgs inputEventArgs)
    {
      if (!base.Matches(targetElement, inputEventArgs)) return false;

      if (!(inputEventArgs is MouseWheelEventArgs)) return false;

      var args = (MouseWheelEventArgs)inputEventArgs;
      return args.Delta < 0;  // We are only interested in wheel down
    }

    #endregion
  }
}
